home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / pcl4c60.zip / SIMPLE32.C < prev    next >
Text File  |  1996-10-24  |  3KB  |  121 lines

  1. /* simple32.c */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <malloc.h>
  6. #include <dos.h>
  7. #include <string.h>
  8. #include <conio.h>
  9.  
  10. #include "pcl4c32.h"
  11. #include "sioerr32.h"
  12.  
  13. #ifndef FALSE
  14. #define FALSE 0
  15. #define TRUE !FALSE
  16. #endif
  17.  
  18. /*** Global Variables ***/
  19.  
  20. int Port = COM1;          /* Port COM1 */
  21. int BaudCode;             /* baud rate code ( index into BaudRate[] ) */
  22. char *BaudRate[10] =  {"300","600","1200","2400","4800","9600",
  23.                        "19200","38400","57600","115200"};
  24.  
  25. long hRxMem;
  26. long hTxMem;
  27. long hMemory;
  28. int  Version;
  29.  
  30. /*** local prototypes */
  31.  
  32. int BaudMatch(char *);
  33. int ErrorCheck(int);
  34.  
  35. /*** main ***/
  36.  
  37. void main(int argc, char *argv[])
  38. {char c;
  39.  int  i, rc;
  40.  if(argc!=3)
  41.    {printf("Usage: SIMPLE32 <port> <baud>\n");
  42.     exit(1);
  43.    }
  44.  /* get port number from command line */
  45.  Port = atoi(argv[1]) - 1;
  46.  if((Port<COM1) || (Port>COM4))
  47.      {printf("Port must be COM1 to COM4\n");
  48.       exit(1);
  49.      }
  50.  /* get baud rate from command line */
  51.  BaudCode = BaudMatch(argv[2]);
  52.  if(BaudCode<0)
  53.      {printf("Cannot recognize baud rate = %s\n",argv[2]);
  54.       exit(1);
  55.      }
  56.  
  57.  /* setup 1024 byte receive buffer */
  58.  ErrorCheck( SioRxBuf(Port,0,Size1024) );
  59.  
  60.  /* setup 128 byte transmit buffer */
  61.  ErrorCheck( SioTxBuf(Port,0,Size128) );
  62.  
  63.  /* reset the port */
  64.  printf("Resetting COM%d: ",1+Port);
  65.  ErrorCheck( SioReset(Port,BaudCode) );
  66.  printf("Port reset\n");;
  67.  
  68.  /* set DTR and RTS */
  69.  ErrorCheck( SioDTR(Port,'S') );
  70.  ErrorCheck( SioRTS(Port,'S') );
  71.  
  72. #if 0
  73.  /* set RTS/CTS flow control */
  74.  ErrorCheck( SioFlow(Port,18) );
  75.  puts("Flow control on");
  76. #endif
  77.  
  78.  /* Set FIFO level */
  79.  if(SioFIFO(Port,LEVEL_8)) printf("[16550]\n");
  80.  else printf("[8250/16450]");
  81.  
  82.  printf("\nEnter terminal loop ( Type ^Z to exit )\n");
  83.  /* enter terminal loop */
  84.  while(TRUE)
  85.      {/* was key pressed ? */
  86.       if(kbhit())
  87.           {i = getch();
  88.            if((char)i==0x1a)
  89.               {/* restore COM port status & exit */
  90.                SioDone(Port);
  91.                puts("DONE.");
  92.                exit(1);
  93.               }
  94.            else SioPutc(Port,(char)i);
  95.           } /* end if */
  96.       /* any incoming over serial port ? */
  97.       i = SioGetc(Port,0);
  98.       ErrorCheck(i);
  99.       if(i>-1) putch((char)i);
  100.      } /* end while */
  101. } /* end main */
  102.  
  103. int ErrorCheck(int Code)
  104. {/* trap PCL error codes */
  105.  if(Code<-1)
  106.      {printf("ERROR %d: ",Code);
  107.       SioError(Code);
  108.       SioDone(Port);
  109.       exit(1);
  110.      }
  111.  return(Code);
  112. } /* end ErrorCheck */
  113.  
  114.  
  115. int BaudMatch(char *P)
  116. {int i;
  117.  /* find baud rate in table */
  118.  for(i=0;i<10;i++) if(strcmp(BaudRate[i],P)==0) return(i);
  119.  return(-1);
  120. }
  121.